package com.yth.extension;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * bean的初始化前后
 *
 * @author yutianhong
 * @version 1.0
 * @since 2023/08/29 16:04:14
 */
@Slf4j
public class TestBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        // bean初始化之前，可以在此对bean进行增强、包装
        log.info("[BeanPostProcessor::postProcessBeforeInitialization] \t>>> beanClass: {}, beanName: {}", bean.getClass().getSimpleName(), beanName);
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        // bean初始化之后，可以在此对bean进行增强、包装
        log.info("[BeanPostProcessor::postProcessAfterInitialization] \t>>> beanClass: {}, beanName: {}", bean.getClass().getSimpleName(), beanName);
        return bean;
    }
}
